package com.zhuss.core.user;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.zhuss.bean.bo.core.user.CareUserRoleListBo;
import com.zhuss.bean.bo.core.user.DetailUserBo;
import com.zhuss.bean.bo.core.user.SearchUserBo;
import com.zhuss.bean.vo.core.user.CareUserRoleListVo;
import com.zhuss.common.ListVo;
import com.zhuss.common.ReadService;
import com.zhuss.core.processor.RoleRead;
import com.zhuss.core.processor.UserRead;
import com.zhuss.core.processor.UserRoleRead;
import com.zhuss.exception.AabException;


/**
 * 用户查询service（基本查询）
 * @author zhushanshuo
 * @Date 2019-12-13 15:59
 *
 */
@Component("userReadService")
public class UserReadService implements ReadService<Object, Object> {
	
	@Autowired
	@Qualifier("userRead")
	private UserRead userRead;
	
	@Autowired
	@Qualifier("roleRead")
	private RoleRead roleRead;
	
	@Autowired
	@Qualifier("userRoleRead")
	private UserRoleRead userRoleRead;
	
	/**
	 * 详情
	 */
	@Override
	public Object detail(Object param) throws AabException {
		DetailUserBo bo = (DetailUserBo) param;
		Long userId = bo.getUserId();
		Object vo = userRead.detail(userId);
		return vo;
	}
	
	/**
	 * 列表
	 * @throws AabException 
	 */
	@Override
	public Object list(Object param) throws AabException {
		SearchUserBo bo = (SearchUserBo) param;
		List<Long> roleIdList = bo.getRoleIdList();
		if (roleIdList != null && !roleIdList.isEmpty()) {
			List<Long> userIdList = userRoleRead.listUserIdByRoleList(roleIdList);
			userIdList.add(0l);
			bo.setUserIdList(userIdList);
			bo.setRoleIdList(null);
		}
		Object result = userRead.list(bo);
		return result;
	}
	
	
	/**
	 * 用户的角色列表
	 * @param bo
	 * @return
	 * @throws AabException 
	 */
	@SuppressWarnings("unchecked")
	public Object careUserRoleList(CareUserRoleListBo bo) throws AabException {
		
		Long userId = bo.getUserId();
		Integer area = bo.getArea();
		CareUserRoleListVo result = new CareUserRoleListVo();
		result.setRoleIdList((List<Long>)userRoleRead.listRoleId(userId));
		result.setRoleList((List<ListVo>)roleRead.listRole(area));
		return result;
	}
	
	
	
}

